<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'login.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<%-- 登陆表单、错误提示 --%>
	<h1>登陆</h1>
	<%
		String uname = "";
		Cookie[] cs = request.getCookies();
		if (cs != null) {
			for (Cookie c : cs) {
				if ("uname".equals(c.getName())) {
					uname = c.getValue();
				}
			}
		}
	%>
	<%
		session.removeAttribute("username");
	
		String msg = request.getAttribute("msg") == null ? ""
				: (String) request.getAttribute("msg");
	%>
	<font color="red"><b><%=msg %></b>
	</font>
	<form action="/java-web-demo/servlet/LoginServlet" method="post">
		用户名：<input type="text" name="username" value="<%=uname %>" /><br /> 
		密码：<input type="text" name="pwd" /><br /> 
		验证码：<input type="text" name="vcode" /> 
		<img id="img" src="/java-web-demo/servlet/VerifyCodeServlet">
		<a href="javascipt:;" onclick="_change();">换一张</a>
		<br />
		<input type="submit" value="登陆" />
	</form>
	
	<script type="text/javascript">
		function _change(){
			var imgVCode = document.getElementById("img");
			imgVCode.src = "/java-web-demo/servlet/VerifyCodeServlet?r="+new Date().getTime();
		}
	</script>	
</body>
</html>
